package com.grts.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.grts.pojo.Classroombean;
import com.grts.service.IClassroomService;
import com.grts.utils.PageModel;

@Controller
@RequestMapping("/classroom")
public class ClassroomController{
	@Resource
	private IClassroomService ics;
	private Map<String,Object> paramMap = new HashMap<String, Object>();
	@RequestMapping("/queryById")
	public String queryById(Map map,@RequestParam(name="cid",required=false)int cid){
		Classroombean csb=ics.selectByPrimaryKey(cid);
		map.put("csb", csb);
		return "../classroom/classroom_add";
	}
	@RequestMapping("/queryByPage")
	public String queryAll(Map map,
			@RequestParam(name="currentPage",defaultValue="1",required=false)int currentPage,
			@RequestParam(name="pageSize",defaultValue="5",required=false)int pageSize,
			@RequestParam(name="cnumber",required=false)String cnumber){
		paramMap.put("currentPage", currentPage);
		paramMap.put("currentSize", (currentPage-1)*pageSize);
		paramMap.put("pageSize", pageSize);
		paramMap.put("cnumber", cnumber);
		PageModel page=ics.queryByPage(paramMap);
		map.put("pageModel", page);
		map.put("cn", cnumber);
		return "../classroom/classroom";
	}
	@RequestMapping("/add")
	public String saveOrUpdate(Classroombean crb){
		if(crb.getCid() !=null && crb.getCid() >0){
			ics.updateByPrimaryKey(crb);
		}else{
			ics.insert(crb);
		}
		return "redirect:queryByPage";
	}
	@RequestMapping("/delete")
	public String delete(@RequestParam(name="cid",required=false)int cid){
		ics.deleteByPrimaryKey(cid);
		return "redirect:queryByPage";
	}
}
